/**
 * 
 */
package com.wbcs.system.component.application.report;

import com.wbcs.config.component.IComponentConfigBean;
import com.wbcs.exception.WbcsRuntimeException;
import com.wbcs.system.ReportRequest;
import com.wbcs.system.component.application.report.abstractreport.AbsRequireChainReportType;
import com.wbcs.system.component.application.report.abstractreport.IActionChain;
import com.wbcs.system.component.application.report.abstractreport.SaveInfoDataBean;
import com.wbcs.system.component.application.report.configbean.editablereport.EditableReportSqlBean;
import com.wbcs.system.component.container.AbsContainerType;
import com.wbcs.system.tags.component.AbsComponentTag;
import com.wbcs.util.Consts_Private;
import com.wbcs.util.Tools;

/**
 * Action Chain报表类型标准实现类
 * @author hawkfly
 */
public class ServerActionType extends AbsRequireChainReportType implements IActionChain {

	private SaveInfoDataBean sidbean;

	public ServerActionType(AbsContainerType parentContainerType,
							IComponentConfigBean comCfgBean, ReportRequest rrequest) {
		super(parentContainerType, comCfgBean, rrequest);
		// TODO Auto-generated constructor stub
	}
	
	public void init(){
		super.init();
		//执行ActionChain类型报表require参数接收及公式解析动作
		
	}

	@Override
	public void displayOnPage(AbsComponentTag displayTag) {
		super.displayOnPage(displayTag);
		forwardParam(rbean.getForwardParam());
	}

	/* (non-Javadoc)
	 * @see com.wbcs.system.component.application.report.abstractreport.IActionChain#forward(java.lang.String)
	 */
	@Override
	public void forwardParam(String paramName) {
		// TODO Auto-generated method stub
		if(Tools.isEmpty(paramName,true))
		{
			throw new WbcsRuntimeException("没有取到转发业务链参数，无法完成上下文设置");
		}

		SaveInfoDataBean sidbean = (SaveInfoDataBean)rrequest.getAttribute(rbean.getId(),"SAVEINFO_DATABEAN");
		if(sidbean != null && (sidbean.hasSavingData()||sidbean.hasDeleteData()))
		{//保存动作执行是否成功
			EditableReportSqlBean ersqlbean=(EditableReportSqlBean)rbean.getSbean().getExtendConfigDataForReportType(EditableReportSqlBean.class);
			if(ersqlbean.getAfterSaveAction().length==2&&"true".equals(ersqlbean.getAfterSaveAction()[1]))
			{//成功保存
				rrequest.setAttribute(paramName, Consts_Private.SAVEREPORT_SUCCESS);
			}
			else
			{
				rrequest.setAttribute(paramName, Consts_Private.SAVEREPORT_FAIL);
			}
		}
		else
		{
			//仅放入查询数据集合，根据分页设置情况不一定是所有查询到的数据
			rrequest.setAttribute(paramName, lstReportData);
		}
	}

	@Override
	public String getReportFamily()
    {
        return Consts_Private.REPORT_FAMILY_CHAIN;
    }

}
